<?php

class Cinema {

    public $id;
    public $title;
    public $story;
    public $projections;
    public $poster;
    public $visible;
    public $order;
    private static $days = array('Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato', 'Domenica');

    public function get_html_movie() {
        ?>
        <div class="row" id="<?= $this->get_div_id() ?>">
            <div class="span3">
                <image src="http://www.salesianichioggia.it/images/<?= $this->poster ?>" class="img-polaroid">
            </div>
            <div class="span4">
                <h2><?= $this->title ?></h2>
                <p><?= $this->story ?></p>
            </div>
            <div class="span2">
                <h2>Orari</h2>
                <ul>
                    <?php foreach ($this->projections as $pr) { ?>
                        <li><strong><?= self::get_day_name($pr['date']) ?> <br/> <?= self::get_readble_date($pr['date']) ?> </strong></li>
                        <ul>
                            <?php foreach ($pr['time'] as $time) { ?>
                                <li>
                                    <?= $time ?>
                                </li>
                            <?php } //end $time 
                            ?>
                        </ul>
                    <?php } //end $date  ?>
                </ul>
            </div>
        </div>
        <?php
    }

    private static function get_readble_date($date_str) {
        list($year, $month, $day) = explode("-", $date_str);
        $months = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
        return $day . " " . $months[$month - 1] . " " . $year;
    }

    private static function get_day_name($date_str) {
        $date = new DateTime($date_str);
        return self::$days[$date->format('N') - 1];
    }

    public function get_div_id() {
        return 'cinema' . $this->id;
    }

}
?>